'''
角色管理页面测试
'''

from Lib.base.page_object.slag_car_manage.slag_car_manage import SlagCarManage
from selenium.webdriver.common.by import By
import allure
import os
from Lib.common.assert_class import AssertClass
import pytest


@pytest.fixture(scope='class', autouse=True)
@pytest.mark.usefixtures('login')
def set_cls(login):
    TestSlagCarTest.assert_class = AssertClass(login)
    TestSlagCarTest.slagCarManager = SlagCarManage(login)


@allure.feature('渣土车管理页面测试')
class TestSlagCarTest:

    @allure.title("新增处置证")
    def test_1_create_disposal(self):
        '''
        新增处置证
        :return:
        '''
        self.slagCarManager.create_disposal()
        # 设置断言
        assert_arg = (By.XPATH, '//p[contains(text(), "新建成功")]')
        self.assert_class.make_assert_by_text(args=assert_arg, assert_data='新建成功', context='新增处置证')

    @allure.title("处置证列表")
    def test_2_disposal_list(self):
        '''
        处置证列表
        :return:
        '''
        self.slagCarManager.disposal_list()
        # 设置断言
        assert_arg = (By.XPATH, '//table[@class="rz-table__body"]/tbody/tr[1]/td[2]/div/span')
        self.assert_class.make_assert_by_text(args=assert_arg, assert_data='沪ATEST1', context='处置证列表')

    @allure.title("编辑处置证")
    def test_3_disposal_update(self):
        '''
        编辑处置证
        :return:
        '''
        self.slagCarManager.disposal_update()
        # 设置断言
        assert_arg = (By.XPATH, '//p[contains(text(), "编辑成功")]')
        self.assert_class.make_assert_by_text(args=assert_arg, assert_data='编辑成功', context='编辑处置证')

    @allure.title("渣土车列表")
    def test_4_slag_car_list(self):
        '''
        渣土车列表
        :return:
        '''
        self.slagCarManager.slag_car_list()
        # 设置断言
        assert_arg = (By.XPATH, '//span[text()="白名单详情"]')
        self.assert_class.make_assert_by_text(args=assert_arg, assert_data='白名单详情', context='渣土车列表')

    @allure.title("删除处置证")
    def test_5_disposal_delete(self):
        '''
        删除处置证
        :return:
        '''
        self.slagCarManager.disposal_delete()
        # 设置断言
        assert_arg = (By.XPATH, '//p[contains(text(), "删除成功")]')
        self.assert_class.make_assert_by_text(args=assert_arg, assert_data='删除成功', context='删除处置证')


if __name__ == '__main__':
    pytest.main(['-v', './slag_car_test.py'])
